package com.hnly.djdl.components

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay

@Composable
fun FallOffAnimation() {
    val yAnimation1 = remember { Animatable(0f) }
    val yAnimation2 = remember { Animatable(0f) }
    val yAnimation3 = remember { Animatable(0f) }
    val yAnimation4 = remember { Animatable(0f) }
    LaunchedEffect(true) {
        delay(1000)
        yAnimation1.animateTo(
            200f,
            //dampingRatio = 阻尼比 , stiffness = 刚度
            //DampingRatioHighBouncy = 阻尼比高弹性  , StiffnessHigh = 刚度高
            animationSpec = spring(
                dampingRatio = Spring.DampingRatioHighBouncy,
                stiffness = Spring.StiffnessHigh,
            )
        )

        yAnimation2.animateTo(
            200f,
            //DampingRatioHighBouncy = 阻尼比高弹性  , StiffnessMediumLow = 刚度中低
            animationSpec = spring(
                dampingRatio = Spring.DampingRatioHighBouncy,
                stiffness = Spring.StiffnessMedium
            )
        )

        yAnimation3.animateTo(
            200f,
            //DampingRatioMediumBouncy = 阻尼比中弹性  , StiffnessMedium = 刚度中
            animationSpec = spring(
                dampingRatio = Spring.DampingRatioMediumBouncy,
                stiffness = Spring.StiffnessLow
            )
        )

        //DampingRatioNoBouncy = 阻尼比无弹性  , StiffnessVeryLow = 刚度非常低
        yAnimation4.animateTo(
            200f,
            animationSpec = spring(
                dampingRatio = Spring.DampingRatioNoBouncy,
                stiffness = Spring.StiffnessVeryLow
            )
        )
    }
    Row(modifier = Modifier.fillMaxSize()) {
        Surface(
            color = Color.Green,
            modifier = Modifier
                .size(40.dp)
                .graphicsLayer {
                    translationY = yAnimation1.value
                }
        ) {}

        Surface(
            color = Color.Green,
            modifier = Modifier
                .size(40.dp)
                .graphicsLayer {
                    translationY = yAnimation2.value
                }
        ) {}

        Surface(
            color = Color.Green,
            modifier = Modifier
                .size(40.dp)
                .graphicsLayer {
                    translationY = yAnimation3.value
                }
        ) {}

        Surface(
            color = Color.Green,
            modifier = Modifier
                .size(40.dp)
                .graphicsLayer {
                    translationY = yAnimation4.value
                }
        ) {}
    }
}